shadow: add _gtk_box_shadow_render()
authorCosimo Cecchi <cosimoc@gnome.org>
Thu, 2 Jun 2011 00:58:53 +0000 (20:58 -0400)
committerBenjamin Otte <otte@redhat.com>
Sat, 11 Jun 2011 07:29:43 +0000 (09:29 +0200)
This supports only inset box-shadow elements for now.

gtk/gtkshadow.c
gtk/gtkshadowprivate.h

index 180c968171f481af090dc4d96ce8716c225da9b9..ebb0df332b4ea9f23ad1a9e52eeab02ae051ebda 100644 (file)
@@ -23,6 +23,8 @@
 
 #include "gtkshadowprivate.h"
 #include "gtkstylecontext.h"
+#include "gtkthemingengineprivate.h"
+#include "gtkthemingengine.h"
 #include "gtkpango.h"
 #include "gtkthemingengineprivate.h"
 
@@ -323,3 +325,44 @@ _gtk_icon_shadow_paint_spinner (GtkShadow *shadow,
       cairo_restore (cr);
     }
 }
+
+void
+_gtk_box_shadow_render (GtkShadow           *shadow,
+                        cairo_t             *cr,
+                        const GtkRoundedBox *padding_box)
+{
+  GtkShadowElement *element;
+  GtkRoundedBox box;
+  GList *l;
+
+  cairo_save (cr);
+  cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
+
+  _gtk_rounded_box_path (padding_box, cr);
+  cairo_clip (cr);
+
+  /* render shadows starting from the last one,
+   * and the others on top.
+   */
+  for (l = g_list_last (shadow->elements); l != NULL; l = l->prev)
+    {
+      element = l->data;
+
+      if (!element->inset)
+        continue;
+
+      box = *padding_box;
+      _gtk_rounded_box_move (&box, element->hoffset, element->voffset);
+      _gtk_rounded_box_shrink (&box,
+                               element->spread, element->spread,
+                               element->spread, element->spread);
+
+      _gtk_rounded_box_path (&box, cr);
+      _gtk_rounded_box_path (padding_box, cr);
+
+      gdk_cairo_set_source_rgba (cr, &element->color);
+      cairo_fill (cr);
+  }
+
+  cairo_restore (cr);
+}
index 08dd3b6df76193a1cbf696e34099954f939d1275..5b9bad5f0c18122ef517ffd9e7ff9fde6c1b9a1b 100644 (file)
 #define __GTK_SHADOW_H__
 
 #include <glib-object.h>
-#include <gtk/gtkstyleproperties.h>
-#include <gtk/gtksymboliccolor.h>
-#include <gtk/gtkicontheme.h>
+
+#include "gtkstyleproperties.h"
+#include "gtksymboliccolor.h"
+#include "gtkicontheme.h"
+#include "gtkcsstypesprivate.h"
+#include "gtkroundedboxprivate.h"
 
 G_BEGIN_DECLS
 
@@ -65,6 +68,9 @@ void       _gtk_icon_shadow_paint_spinner (GtkShadow *shadow,
                                            cairo_t   *cr,
                                            gdouble    radius,
                                            gdouble    progress);
+void       _gtk_box_shadow_render         (GtkShadow           *shadow,
+                                           cairo_t             *cr,
+                                           const GtkRoundedBox *padding_box);
 
 G_END_DECLS